<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <script type="text/javascript" src="./script/rem.js"></script>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/jquery.min.js"></script>

    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/api.js"></script>
</head>
<body>
<style>
body{background:url(./image/wallet-bg.png) #f1f2f4 0 -1.5rem no-repeat; background-size:100% auto;}
</style>

<header class="wallet-head" style="padding-top:0.4rem;">
    <div class="wallet-head-l" tapmode onclick="closeWin()"><i class="fa fa-angle-left"></i></div>
    <h3></h3>
    <!-- <div class="wallet-head-r" tapmode onclick="user_wallet_recharge()">充值记录</div> -->
</header>

<!-- <div class="wallet-t">
    <img id="user_image" class="wallet-t-t" src="image/gril.png"> -->
    <!-- <div class="wallet-t-d">
    <img id="user_wallet-level" class="wallet-t-d" src="image/wallet-level-3.png" style="display: none;"> 
    </div>
</div>-->
<div class="wallet-m">
    <!--<div class="wallet-m-l">
         当前可用赚石
        <p>80000</p> 
    </div>-->
    <div class="wallet-m-m">
        <!-- 可提现奖金 -->
        团队组建奖
        <p>
            ￥<i id="money">0</i>
        </p>
        <span>每月15号后，可提现上月奖励</span>
    </div>
    <!-- <div class="wallet-m-l">
        XXX金币
        <p>50</p>
    </div> -->
</div>

<div class="wallet-btn" tapmode onclick="wallet_pick();">提现</div>

<!-- 无记录 -->
<div class="wallet-d-no" id="wallet-record">
    <img src="image/wallet-d-no.png">
    <p>无提现记录啦！</p>
</div>

<!-- 有记录 -->
<div style="display:none;" id="list-id">
    <div class="wallet-d">
        <i></i>
        <span>提现记录</span>
        <i></i>
    </div>
    <div id="wallet-record-3">
        <!-- <ul class="wallet-list">
            <li>
                <dl>
                    <dt>提现<span>￥500</span></dt>
                    <dd>2018-02-05</dd>
                </dl>
                <p>-50币</p>
            </li>
            <li>
                <dl>
                    <dt>提现<span>￥500</span></dt>
                    <dd>2018-02-05</dd>
                </dl>
                <p>-50币</p>
            </li>
            <li>
                <dl>
                    <dt>提现<span>￥500</span></dt>
                    <dd>2018-02-05</dd>
                </dl>
                <p>-50币</p>
            </li>
            <li>
                <dl>v
                    <dt>提现<span>￥500</span></dt>
                    <dd>2018-02-05</dd>
                </dl>
                <p>-50币</p>
            </li>
            <li>
                <dl>
                    <dt>提现<span>￥500</span></dt>
                    <dd>2018-02-05</dd>
                </dl>
                <p>-50币</p>
            </li>
        </ul> -->
    </div>
</div>

<script type="text/template" id="wallet-list-id">
    <div class="wallet-d">
        <i></i>
        <span>提现记录</span>
        <i></i>
    </div>
    {{~it.data:value:index}}
    <ul class="wallet-list">
        <li>
            <dl>
                <!-- <dt>提现<span>￥{{=value.amount}}</span></dt> -->
                <dt>提现</dt>
                <dd>{{=value.time}}</dd>
            </dl>
            <p>-￥{{=value.amount}}</p>
        </li>
    </ul>
    {{~}}
</script>

</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/index.js"></script>
<script type="text/javascript">
    apiready = function(){
        user_info();
        history_coin();
        initRefresh();
        pullLoading();
        reloadListener();
    }

    function user_info(){
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });
        var token = $api.getStorage('token');
        api.ajax({
             url: webAddress + '/api/auth/info',
             method: 'get',
             data: {
                 values: { 
                    
                 },
             },
             headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
             },
         },function(ret, err){
             if (ret) {
                 api.hideProgress();
                 // alert( JSON.stringify( ret ) );
                 $api.byId('money').innerHTML = ret.data.wage;
                 money = ret.data.wage;
                 // $api.byId('user_image').src = ret.data.avatar;
                 // var level = $api.byId('user_wallet-level');
                 // if(ret.data.level == 1){
                 //    level.style.display='block';
                 //    level.src = "image/wallet-level-1.png";
                 // }else if(ret.data.level == 2){
                 //    level.style.display='block';
                 //    level.src = "image/wallet-level-2.png";
                 // }else if(ret.data.level == 3){
                 //    level.style.display='block';
                 //    level.src = "image/wallet-level-3.png";
                 // }else if(ret.data.level == 4){
                 //    level.style.display='block';
                 //    level.src = "image/wallet-level-4.png";    
                 // }
             } else {
                 // alert( JSON.stringify( err ) );
             }
         }); 
    }

    function history_coin(more){
        // 进度提示框
        api.showProgress({
            title: '努力加载中...',
            text: '请稍等...',
            modal: false
        });
        if (more) {
            page += 1;
        }else{
            page = 1;
        }
        var token = $api.getStorage('token');
        api.ajax({
            url: webAddress + '/api/user/wallet/history/coin',
            method: 'get',
            data: {
                values: { 
                    page: 1,
                    row: row,
                },
            },
            headers: {
                Authorization: 'Bearer ' + token,
                Accept: 'application/json',
            },
        },function(ret, err){
            if (ret) {
                // alert( JSON.stringify( ret ) );
                // 关闭上拉加载控件
                api.hideProgress();
                api.refreshHeaderLoadDone(); //下拉刷新关闭
                if (ret.data && ret.data != "") {
                  templateFun(ret,more);
                }
            } else {
                // alert( JSON.stringify( err ) );
                api.toast({
                  msg: err.body.message,
                  duration: 2000,
                  location: 'bottom'
                });
                return false;
            }
        });
    }


    function templateFun(data,more){
        var wallet1 = $api.byId('wallet-record');
        var wallet2 = $api.byId('list-id');       
        wallet1.style.display='none';
        wallet2.style.display='block';
        var wallet = $api.byId('wallet-list-id');
        var dotFn = doT.template(wallet.innerHTML);
        var html = dotFn(data);
        var list = $api.byId('list-id');
        if (more) {
            if (data.length) {
              $api.append(list, html);
            }else{
             api.toast({
              msg: '没有啦！',
              duration: 2000,
              location: 'bottom'
            });
             return; 
            }
        }else{
          // if (data.length) {
           $api.html(list, html);
          // }
        }
    }

    // 上拉加载
    function pullLoading(){
      api.addEventListener({
        name: 'scrolltobottom',
        extra: {
          threshold: 0
        }
      }, function(ret, err){
        history_coin(1);
      });
    }

    // 下拉刷新
    function initRefresh() {
    api.setRefreshHeaderInfo({
        visible: true,
        // loadingImg: 'widget://image/gril.png',
        bgColor: '#ccc',
        textColor: '#fff',
        textDown: '下拉刷新...',
        textUp: '松开刷新...',
        showTime: true
    }, function(ret, err){
        history_coin();
    });
};

    //提现
    function wallet_pick(){
        // if(money == 0){
        //     api.toast({
        //         msg: '余额不足',
        //         duration: 2000,
        //         location: 'bottom'
        //     });
        //     return false;
        // }
        api.openWin({
            name: 'new_pay_password',
            url: 'new_pay_password.html',
            pageParam: {
                name: 'test'
            }
        });
    }
    // function wallet_pick(){
    //     var token = $api.getStorage('token');
    //     api.ajax({
    //         url: webAddress + '/api/user/wallet/pick',
    //         method: 'post',
    //         data: {
    //             values: { 
                   
    //             },
    //         },
    //         headers: {
    //             Authorization: 'Bearer ' + token,
    //             Accept: 'application/json',
    //         },
    //     },function(ret, err){
    //         if (ret) {
    //             // alert( JSON.stringify( ret ) );
    //             if (ret.status_code == 200) {
    //                 api.toast({
    //                     msg: ret.message,
    //                     duration: 2000,
    //                     location: 'bottom'
    //                 });
    //                 user_info();
    //                 history_coin();
    //             }
    //         } else {
    //             // alert( JSON.stringify( err ) );
    //             if (err.statusCode == 400) {
    //                 api.toast({
    //                     msg: err.body.message,
    //                     duration: 2000,
    //                     location: 'bottom'
    //                 });
    //                 return false;
    //             }
    //         }
    //     });
    // }



    function user_wallet_recharge() {
        api.openWin({
            name: 'user_wallet_recharge',
            url: './user_wallet_recharge.html',
        });
    }

    function closeWin(){
        api.closeWin({
        });
    }

    // 监听事件 (页面刷新)
    function reloadListener() {
        api.addEventListener({
            name: 'user_wallet',
        }, function(ret, err) {
            user_info();
            history_coin();
        });
    }
</script>
</html>